import VeeValidate from "vee-validate";
import zh_CN from "vee-validate/dist/locale/zh_CN.js";
export default function (Vue) {
  Vue.use(VeeValidate);
  //配置中文包(必须等插件使用后才能进行配置)
  VeeValidate.Validator.localize("zh_CN", {
    messages: {
      ...zh_CN.messages,
      is: (n) => n + "的值必须和上边的值相等",
    },
    //把表单校验的名字映射成中文
    attributes: {
      phone: "手机号码",
      code: "验证码",
      password: "密码",
      passwordAgain: "重复密码",
      agree: "规则",
    },
  });

  //给Vee-validata扩展规则
  VeeValidate.Validator.extend("isAgree", {
    validate: (value) => {
      //自定义校验规则的回调函数接受当前的表单的值作为参数,如果在我们的规则下通过则返回true,否则返回false
      /* if (value === true) {
      return true;
    } else {
      return false;
    } */
      return value;
    },
    //配置错误提示
    getMessage: (n) => {
      return n + "必须同意";
    },
  });
}